package 我的Java学习_算法基础.day_04;

import java.util.Scanner;

public class _068_矩阵运算加减法 {
    /**
     * a:
     * 3 -1 2
     * 1 5 7
     * 2 4 5
     * b:
     * 7 5 -2
     * 5 1 9
     * 4 2 1
     *a+2x=b
     * 3 -1 2 1 5 7 2 4 5       7 5 -2 5 1 9 4 2 1
     *
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m,n;
        m=scanner.nextInt();
        n = scanner.nextInt();
        System.out.println("请输入两矩阵：");
        int[][] a= new int[m][n];
        int[][] b= new int[m][n];
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                a[i][j] = scanner.nextInt();
            }
        }
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                b[i][j] = scanner.nextInt();
            }
        }
        int[][] x =getX(a,b);
        print(x);
    }
    private static void print(int[][] x) {
        int m = x.length;
        int n = x[0].length;
        for(int i =0;i<m;i++){
            for(int j =0;j<n;j++){
                System.out.print(x[i][j]+"\t");
            }
            System.out.println();
        }
    }

    //a+2x=b;
    private static int[][] getX(int[][] a,int[][] b){
        int m =a.length;
        int n = a[0].length;
        int[][] x = new int[m][n];
        for(int i = 0;i<m;i++){
            for(int j = 0;j<n;j++){
                x[i][j] = (b[i][j]-a[i][j])/2;
            }
        }
        return x;
    }
}
